#ifndef AHXGWNET_IOWRAPPER_H_
#define AHXGWNET_IOWRAPPER_H_

#include <sys/types.h>
#include "proto.h"

namespace ahxgwnet {

/**
 * 封装阻塞socket读写
 */
class IOWrapper {
public:
    IOWrapper() {}
    IOWrapper(int fd);
    void setFd(int fd);
    ssize_t readN(void *vptr, size_t n);
    ssize_t writeN(const void *vptr, size_t n);
    ssize_t readLine(void *vptr, size_t maxLen);
    ssize_t readLineBuf(void **vptrptr);

private:
    ssize_t myRead(char *ptr);

    int     m_fd;
    int     m_readCnt;          /* myRead中读的字节数 */
    char    *m_readPtr;         /* myRead中读的指针 */
    char    m_readBuf[MAXLINE]; /* myRead中读取的缓存 */
};

}

#endif
